<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <IndexTitle ref="top"></IndexTitle>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="审计单位">
              <j-select-depart
                v-model="queryParam.sjdw"
                :trigger-change="true"
                customReturnField="id"
                :multi="false"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="被审计单位">
              <j-select-depart
                v-model="queryParam.bsjdw"
                :trigger-change="true"
                customReturnField="id"
                :multi="false"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="计划年度">
              <a-date-picker
                mode="year"
                placeholder="请选择年份"
                format="YYYY"
                value-format="yyyy-MM-dd"
                v-model="queryParam.year"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!--            <a-col :md="6" :sm="8">-->
            <!--              <a-form-item label="项目阶段">-->
            <!--                <j-dict-select-tag style='width: 100%' v-model="queryParam.stage" placeholder="请选择"-->
            <!--                                   dict-code="sjzystage"/>-->
            <!--              </a-form-item>-->
            <!--            </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="项目类别">
                <j-dict-select-tag
                  style="width: 100%"
                  v-model="queryParam.type"
                  placeholder="请选择"
                  dict-code="pro_type"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="项目编号">
                <a-input placeholder="请输入" v-model="queryParam.number"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="项目名称">
                <a-input placeholder="请输入" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="name" slot-scope="text">
          <j-ellipsis :value="text" :length="20" />
        </span>
        <span slot="bsjdwName" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>
        <span slot="action" slot-scope="text, record">
          <a
            @click="
              handleEdit(
                record,
                `${record.name}（${record.stageText}) —— 审计起止日期：${record.startDate}/${record.endDate}`,
                false
              )
            "
            >详情</a
          >
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <content-view ref="modalForm" @ok="updateProList"></content-view>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import IndexTitle from './IndexTitle'
import columns from './indexColumns'
import moment from 'moment'
import 'moment/locale/zh-cn'
import { httpAction, getAction } from '@/api/manage'
import contentView from './contentView'
import { mapGetters } from 'vuex'
import { currentY } from '@/mixins/commontime'

export default {
  name: 'sjxmss',
  mixins: [JeecgListMixin],
  components: {
    IndexTitle,
    contentView,
  },
  data() {
    return {
      queryParam: {
        year: currentY(),
      },
      superParam: {
        userId: this.userInfo().id,
        stage: '020',
      },
      // 表头
      columns: columns(this),
      url: {
        list: '/sjxmzygl/sjWorkProjectInfo/queryWorkProjectList',
        top: '/sjxmzygl/sjWorkProjectInfo/queryWorkProjectNumber',
      },
      yearPickShow: false,

      // 跳转过来用的
      activeKey: undefined,
      activeValue: undefined,
    }
  },
  created() {
    this.getTop()
  },
  watch: {
    $route: {
      handler: function (to) {
        // 如果有就是别的页跳过来的
        if (to.query.number) {
          this.disableMixinCreated = true
          this.queryParam.number = to.query.number
          this.searchQuery()
        }
        // 审计结果页跳过来的
        if (to.query.activeKey) {
          let { activeKey, activeValue, record } = to.query
          this.$nextTick(() => {
            this.activeKey = activeKey
            this.activeValue = activeValue
            this.handleEdit(
              JSON.parse(record),
              `${JSON.parse(record).name}（${JSON.parse(record).stageText}) —— 审计起止日期：${
                JSON.parse(record).startDate
              }/${JSON.parse(record).endDate}`,
              true
            )
          })
        }
      },
      immediate: true,
    },
  },
  computed: {},
  methods: {
    ...mapGetters(['userInfo']),
    // 被审计单位
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
      if(this.queryParam.year){
        this.queryParam.year = moment(this.queryParam.year.slice(0, 4)).format('YYYY')
      }
    },
    handleEdit(record, name, isbanRouterParams) {
      //isbanRouterParams 禁止使用路由参数   true：标识使用路由参数，false：标识不适用路由参数
      this.$refs.modalForm.edit(record,isbanRouterParams)
      this.$refs.modalForm.title = name
      this.$refs.modalForm.isCheck = false
      this.$refs.modalForm.disableSubmit = false
      // this.$refs.modalForm.isbanRouterParams = isbanRouterParams
    },
    moment,
    // 得到年份选择器的值
    handlePanelChange(value) {
      this.yearPickShow = false
      this.queryParam.year = moment(value).format('YYYY')
    },
    // 头部信息
    getTop() {
      getAction(this.url.top, Object.assign({}, this.queryParam, this.superParam, { eve: 1 }))
        .then((res) => {
          if (res.success) {
            this.$refs.top.r1 = res.result[0].number1
            this.$refs.top.r2 = res.result[0].number2
            this.$refs.top.r3 = res.result[0].number3
          }
        })
        .finally(() => {})
    },
    updateProList() {
      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>